Imports System
Imports System.ComponentModel
Imports NUnit.Framework
Imports ValidationFramework

Namespace BusinessBaseClasses
    Public Class NotifyBaseStringExample
#Region "Example"
        Public Class Person
            Inherits NotifyBase


            ' Fields
            Private _emailAddress As String
            Public Const EmailAddressMember As String = "EmailAddress"
            Private _firstName As String
            Public Const FirstNameMember As String = "FirstName"
            Private _lastName As String
            Public Const LastNameMember As String = "LastName"

            ' Properties
            Public Property EmailAddress() As String
                Get
                    Return _emailAddress
                End Get
                Set(ByVal value As String)
                    If (Not _emailAddress Is value) Then
                        _emailAddress = value
                        MyBase.NotifyPropertyChanged(EmailAddressMember)
                    End If
                End Set
            End Property

            Public Property FirstName() As String
                Get
                    Return _firstName
                End Get
                Set(ByVal value As String)
                    If (Not _firstName Is value) Then
                        _firstName = value
                        MyBase.NotifyPropertyChanged(FirstNameMember)
                    End If
                End Set
            End Property

            Public Property LastName() As String
                Get
                    Return _lastName
                End Get
                Set(ByVal value As String)
                    If (Not _lastName Is value) Then
                        _lastName = value
                        MyBase.NotifyPropertyChanged(LastNameMember)
                    End If
                End Set
            End Property


        End Class


        <TestFixture()> _
        Public Class ExampleUsage


            ' Fields
            Private firstNameEventFired As Boolean

            ' Methods
            Private Sub person_PropertyChanged(ByVal sender As Object, ByVal e As  _
                                                  PropertyChangedEventArgs)
                ' Check that it is the property we are interested in
                If (e.PropertyName Is Person.FirstNameMember) Then
                    firstNameEventFired = True
                End If
            End Sub

            <Test()> _
            Public Sub RunEvent()
                Dim _person As New Person

                ' Attach to PropertyChanged so we are notified 
                AddHandler _person.PropertyChanged, AddressOf person_PropertyChanged

                ' Set FirstName and hence firing the event
                _person.FirstName = "John"

                ' Since the event has fired the firstNameEventFired flag will be true;
                Assert.IsTrue(firstNameEventFired)
            End Sub


        End Class
#End Region
    End Class
End Namespace